<?php
class ScoreHelper extends AppHelper {

	var $helpers = array('Html');
	
	var $defaultSettings = array(
		'width' => '110px',
		'innerColor' => '#F15A24',
		'borderColor' => 'none',
		'backgroundColor' => '#666'
	);

	function outputCss($options)
	{
		$options = am($this->defaultSettings, $options);
		$view =& ClassRegistry::getObject('view');
		$view->addScript(
		'<style>div.progress-'.$this->domId.' {
		  border: 1px solid '.$options['borderColor'].'; 
		  width: '.$options['width'].'; 
		  margin: 2px 5px 2px 0; 
		  
		  float: left; 
		  -moz-border-radius:10px;
		  -webkit-border-radius: 10px;
		  background: '.$options['backgroundColor'].';
		}
		
		div.progress-'.$this->domId.' > div {
		  background-color: '.$options['innerColor'].'; 
		  height: 10px;
		  -moz-border-radius:10px;
		  -webkit-border-radius:10px;
		}
		</style>');
	}

	// n out of 10 score display function
	function show($score=null, $total = 10, $options = array())
	{
		$this->domId = mt_rand();
		
		$this->outputCss($options);
		
		$percentage = 0;
		
		if(!is_null($score))			
			$percentage = 100 * ($score / $total);
		else
			$score = 'N/A'; //return N/A if we don't send any argument
			
		//echo $percentage; exit;
		if(isset($options['showPercent']) && $options['showPercent']==1)
			$score = round($percentage).'%';
		$code = '<div class="progress-'.$this->domId.'">          
					<div style="width: '.$percentage.'%"></div>
				</div></td><td width="10px"><div>'.$score.'</div></td>';
		echo $code;
	}

}
?>